
$(document).ready(function(){
	/**登陆**/

	$('#login').click(function (){
		var username = $('#username').val();
		var pwd = $('#pwd').val();
		var remember = $('#remember').val();
		var equip = $('#equip').val();
		var utype = $('#utype').val();
        var save = $('#save').val();
        if(save!='save'){
        	save = 'hello';
        }
		if(username == "" || pwd == ""){
			if(equip == "wx"){
				dialogShow('手机号（用户名）密码不能为空');
			}else{
				alert('手机号（用户名）密码不能为空');
			}
			
			return false;
		}else{
			mobile = /^(13|14|15|17|18|19)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
			if(!mobile.test(username)){
				if(equip == "wx"){
					dialogShow('请正确填写手机号（用户名）');
				}else{
					alert('请正确填写手机号（用户名）');
				}
				
				return false;
			}
		}
		

		if($("#huan").text()=='个人'){
			ajax_url = '/user_login';
		}else{
			ajax_url = '/company_login';
		}

		var token = $('#token').val();
		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "post",
			data:{"username":username,"pwd":pwd,"token":token,"save":save},
			dataType: "json",
			error:function(){
				alert('服务器维修.请稍后...');
			},
			success:function(data){
				if(data.code=='1'){		
					window.location.href = '/index';
				}else{
					alert(data.msg);
				}
			}
		});
	});
    
    /**新版企业端登陆**/
	$('#company_login').click(function (){
		var username = $('#company_username').val();
		var pwd = $('#company_pwd').val();
		var remember = $('#remember').val();
        var yzm = $("#company_yzm").val();
        
		if(username == "" || pwd == ""){
		    alert('手机号（用户名）密码不能为空');
			return false;
		}else{
            mobile = /^(13|14|15|17|18|19)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
            if(!mobile.test(username)){
                alert('请正确填写手机号（用户名）');
                return false;
            }
		}
        
        if(!yzm){
            alert('请填写验证码');
            return false;
        }
		
		$("#login").attr('disabled',true);

		var ajax_url = "login.php?act=login_do&utype=2&needyzm=1&yzm="+yzm;
		ajax_url = ajax_url+"&remember="+remember+"&pwd="+pwd+"&username="+username+"&t="+new Date().getTime();

		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "post",
			dataType: "json",
			error:function(){
				alert('登录失败');
				$("#login").attr('disabled',false);
			},
			success:function(rs){
				
				if(rs[0]==0){
					alert(rs[1]);
					$("#login").attr('disabled',false);
				}else{
				    location.href=rs[1];
				}
			}
		});
	});

	/**注册**/
	$('#regist').click(function(){
		var username = $('#username').val();
		var pwd = $('#pwd').val();
		var repwd = $('#repwd').val();
		var auth = $('#auth').val(); //手机验证码
		var utype = $('#utype').val();  //1 个人 2 企业
		if(username == ""){
				alert('手机号（用户名）不能为空');
			
			return false;
		}
		if(pwd == ""){

				alert('密码不能为空');

			return false;
		}
		if(repwd == ""){
			alert('确认密码不能为空');
		
			return false;
		}
		if(auth == ""){
				alert('手机验证码不能为空');

			
			return false;
		}

		if(pwd != repwd){

				alert('密码不一致，请重新填写');
			
			return false;
		}

		mobile = /^(13|14|15|17|18|19)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
		if(!mobile.test(username)){
				alert('请正确填写手机号（用户名）');

			return false;
		}
		if(utype==1){
			ajax_url = '/index/login/reguser';
		}else{
			ajax_url = '/index/login/regcompany';
		}
		 
		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "post",
			dataType: "json",
			data:{'username':username,"pwd":pwd,"auth":auth},
			error:function(){
			},
			success:function(rs){
				if(rs.code==0){
					alert(rs.msg);
				}else{
					window.location.href = '/index/login/index';
				}
			}
		});

	});

	//企业修改密码
		$('#companypwd').click(function(){
		var username = $('#username').val();
		var pwd = $('#pwd').val();
		var repwd = $('#repwd').val();
		var auth = $('#auth').val(); //手机验证码
		if(username == ""){
				alert('手机号（用户名）不能为空');
			
			return false;
		}
		if(pwd == ""){

				alert('密码不能为空');

			return false;
		}
		if(repwd == ""){
			alert('确认密码不能为空');
		
			return false;
		}
		if(auth == ""){
				alert('手机验证码不能为空');

			
			return false;
		}

		if(pwd != repwd){

				alert('密码不一致，请重新填写');
			
			return false;
		}

		mobile = /^(13|14|15|17|18|19)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
		if(!mobile.test(username)){
				alert('请正确填写手机号（用户名）');

			return false;
		}
		 
		$.ajax({
			url: '/index/login/companypwd',
			timeout: 5000,
			type: "post",
			dataType: "json",
			data:{'username':username,"pwd":pwd,"auth":auth},
			error:function(){
			},
			success:function(rs){
				if(rs.code==0){
					alert(rs.msg);
				}else{
					window.location.href = '/index/login/index';
				}
			}
		});

	});

	
	/**收藏/取消收藏企业**/
	$('#collect_company').click(function(){
		var company_id = $("#company_id").val();
		var collectcompany = $('#collectcompany').val();
		/**动作**/
		if(collectcompany == 1){
			collectcompany = 2;
		}else{
			collectcompany = 1;
		}

		$.ajax({
			url: '/index/index/collectcompany',
			type: "POST",
			data:{"c_id":company_id,'collectcompany':collectcompany},
			dataType: "json",
			error: function(){
				alert('操作失败！！！');
			},
			success:function(rs){

				if(rs.code==0){
					alert(rs.msg);
					if(rs.msg=='未登录'){
						window.location.href = 'http://www.zzz.com/index/login/index';
					}
				}else{
					if(rs.msg=='已收藏'){
						$("#collectcompany").val('1') ;
						$('#collect_company').attr("class","sc-on");
					}else{
						$("#collectcompany").val('2') ;
						$('#collect_company').attr("class","sc");
					}
				}
			}
		});
	});
	/**收藏/取消收藏职位**/
	$('#collect_job').click(function(){
		var iscollect = $("#iscollect").val();
		var job_id = $("#job_id").val();
		/**动作**/
		if(iscollect == 1){
			iscollect = 2;
		}else{
			iscollect = 1;
		}

		$.ajax({
			url: '/index/index/collect',
			type: "POST",
			data:{"job_id":job_id,'iscollect':iscollect},
			dataType: "json",
			error: function(){
				alert('操作失败！！！');
			},
			success:function(rs){

				if(rs.code==0){
					alert(rs.msg);
					window.location.href = 'http://www.zzz.com/index/login/index';
				}else{
					if(rs.msg=='已收藏'){
						$("#iscollect").val('1') ;
						$('#collect_job').attr("class","sc-on");
					}else{
						$("#iscollect").val('2') ;
						$('#collect_job').attr("class","sc");
					}
				}
			}
		});
		
	});
	/**继续报名职位**/
	$('#apply_job_continue').click(function(){
		var job_id = $("#job_id").val();
		var equip = $('#equip').val();
		var worktime = $("#worktime").val();

		var is_continuity = $("#is_continuity").val();//是否是连续工作

	    //如果有地图
        var mapxy = $("#mapxy").val();
        if(mapxy == 1){
            var mappos = $('#mappos').val();

            if(!mappos){
               if(equip == 'wx'){
                 alert("请选择工作地点");
               }else{
                 alert("请选择工作地点");
               }
               return false;
            }
        }

		if(worktime == ""){
			if(equip == 'wx'){
				alert("请选择报名时间！");
			}else{
				alert("请选择报名时间！");
			}
			
			return false;
		}
		if(typeof($("#fullname").val()) == 'undefined' ){
			var fullname = '';
		}else{
			var fullname = $("#fullname").val();
			if(fullname == ""){			
                if(equip == 'wx'){
				    alert("请填写姓名!");
                }else{
                    alert('请填写姓名!');
                }
                return false;
			}
		}
		if(typeof($("#sex").val()) == 'undefined'){
			var sex = '';
		}else{
			var sex = $("#sex").val();
			if(sex == ""){			
                if(equip == 'wx'){
				    alert("请填写性别!");
                }else{
                    alert("请填写性别!");
                }
                return false;
			}
		}
	
		if(typeof($("#card_id").val()) == 'undefined' ){
			var card_id = '';
		}else{
			var card_id = $("#card_id").val();
			if(card_id == ""){
				if(equip == 'wx'){
					alert("请填写身份证号!");
				}else{
					alert("请填写身份证号!");
				}
				return false;
			}else{
				var card_rule = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
				if(!IdentityCodeValid(card_id)){
					if(equip == 'wx'){
						alert("请填写正确的身份证号！");
					}else{
						alert("请填写正确的身份证号！");
					}
					return false;
				}
			}
		}
		if(typeof($("#worktime").val()) == 'undefined'){
			var worktime = '';
		}else{
			var worktime = $("#worktime").val();
			if(worktime == ""){			
				dialogShow("请选择时间!");
			}
		}
		/**动作**/
		var	state = 1;
        if(equip == 'wx'){
            var is_from = 5; 
        }else{
            var is_from = 6;
        }

		var ajax_url = "index.php?act=apply_job&state="+state+"&job_id="+job_id+"&worktime="+worktime+"&card_id="+card_id+"&sex="+sex+"&fullname="+fullname+"&marker="+mappos+"&t="+new Date().getTime()+'&is_from='+is_from;

        $("#apply_job_continue").attr('disabled',true);
		$.ajax({
			url: ajax_url,
			timeout: 10000,
			type: "POST",
			dataType: "json",			
			error: function(){	
                $("#apply_job_continue").attr('disabled',false);
				if(equip == "wx"){
					alert('申请失败！！！');
				}else{
					alert('申请失败！！！');
				}
			},
			
			success:function(rs){
                $("#apply_job_continue").attr('disabled',false);
				if(rs[0]==1){
					if(equip == "wx"){
						alert(rs[1]);
						/*if($("#job_apply").val() == 2){
							$('.ui-btn-lg').show();
							$('.ui-btn-lg').css('width','50%');
							$('#continue_button').css('width','100%');
							$('#continue_button').html('继续报名') ;
							$("#job_apply").val('1');
						}*/
                        location.reload();
					}else{
						alert(rs[1]);
						location.reload();
					}
				}else if(rs[0]==2){
					if(equip == "wx"){
						location.href=rs[1]+"?equip="+equip;
					}else{
						location.href=rs[1];
					}
					
				}else{
					if(equip == "wx"){
						alert(rs[1]);
					}else{
						alert(rs[1]);
					}
				}
			}
		});
	});
	/**申请/取消申请职位**/
	$('#apply_job').click(function(){
		var state_tmp = $("#job_apply").val();//1已经报名，2没报名
		var job_id = $("#job_id").val();
		var equip = $('#equip').val();
		var worktime = $("#worktime").val();
        var type=$("#type").val();
		var is_continuity = $("#is_continuity").val();//是否是连续工作
        
        //如果有地图
        var mapxy = $("#mapxy").val();
        if(state_tmp == 2 && mapxy == 1){
            var mappos = $('#mappos').val();
            if(!mappos){
               alert("请选择工作地点");
               return false;
            }
        } 
	
		if(typeof($("#fullname").val()) == 'undefined' || state_tmp == 1){
			var fullname = '';
		}else{
			var fullname = $("#fullname").val();
			if(fullname == ""){			
				alert("请填写姓名!");
			}
		}
		if(typeof($("#sex").val()) == 'undefined' || state_tmp == 1){
			var sex = '';
		}else{
			var sex = $("#sex").val();
			if(sex == ""){			
				alert("请填写性别!");
			}
		}
		if(typeof($("#card_id").val()) == 'undefined' || state_tmp == 1){
			var card_id = '';
		}else{
			var card_id = $("#card_id").val();
			if(card_id == ""){
				if(equip == 'wx'){
                    /*判断是否登录、个人登录*/
                    if(type==1){
                        var card_rule = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
                        if(!IdentityCodeValid(card_id)){
                            if(equip == 'wx'){
                                alert("请填写正确的身份证号！");
                            }else{
                                alert("请填写正确的身份证号！");
                            }
                            return false;
                        }
                    }else{
                        alert("请先登录");
                        return false;
						/*setTimeout(function(){
							location.href="login.php?equip=wx&act=choice";
						},3000);*/
                    }
				}else{
					alert("请填写身份证号!");
				}
				return false;
			}else{
				var card_rule = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
				if(!IdentityCodeValid(card_id)){
				//if(!card_rule.test(card_id)){
					if(equip == 'wx'){
						alert("请填写正确的身份证号！");
					}else{
						alert("请填写正确的身份证号！");
					}
					return false;
				}
			}
		}
		if(is_continuity == 2 && state_tmp == 2){//不连续的工作
			if(worktime == ""){
				if(equip == 'wx'){
					alert("请选择报名时间！");
				}else{
					alert("请选择报名时间！");
				}

				return false;
			}
		}
		if(typeof($("#worktime").val()) == 'undefined'){
			var worktime = '';
		}else{
			var worktime = $("#worktime").val();
			if(worktime == "" && (equip != 'wx' || (state_tmp != 1 && equip == 'wx'))){			
				alert("请选择时间!");
				return false;
			}
		}
		/**动作**/
		if(state_tmp == 1){
			state = 2;
		}else{
			state = 1;
		}
        
        if(equip == 'wx'){
            var is_from = 5; 
        }else{
            var is_from = 6;
        }


        if(state == 2 && equip == "wx"){
            var ajax_url = "index.php?act=apply_job_wx&state="+state+"&job_id="+job_id+"&worktime="+worktime+"&card_id="+card_id+"&sex="+sex+"&fullname="+fullname+"&marker="+mappos+"&t="+new Date().getTime();
        }else{
            var ajax_url = "index.php?act=apply_job&state="+state+"&job_id="+job_id+"&worktime="+worktime+"&card_id="+card_id+"&sex="+sex+"&fullname="+fullname+"&marker="+mappos+"&t="+new Date().getTime()+'&is_from='+is_from;
        }
        
        $("#apply_job").attr('disabled',true);
		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){	
                $("#apply_job").attr('disabled',false);
				if(equip == "wx"){
					dialogShow('申请失败！！！');
				}else{
					alert('申请失败！！！');
				}
			},
			success:function(rs){
                $("#apply_job").attr('disabled',false);
				if(rs[0]==1){
					if(equip == "wx"){
						
					    alert(rs[1]);
                        location.reload();
						/*if(is_continuity == 1){//连续工作
							if(state_tmp == 1){
								$("#job_apply").val('2') ;
								$(".apply_button").html('立刻报名') ;
							}else{
								$("#job_apply").val('1') ;
								$(".apply_button").html('取消报名') ;
							}
						}else{
							if(state_tmp == 1){//取消报名
								$('#apply_job_continue').hide();
								$('.apply_job').show();
								$('.ui-btn-lg').hide();
								$('#continue_button').css('width','100%');
								$('#continue_button').html('立刻报名') ;
								$('#continue_button').show() ;
								$("#job_apply").val('2') ;
							}else{//报名操作
								$('.apply_job').hide();
								$('#apply_job_continue').show();
								$('.ui-btn-lg').css('width','50%');
								$('#continue_button').show();
								$("#job_apply").val('1') ;
								//$(".apply_button").html('取消报名') ;
								$(".apply_button").hide() ;
								$(".quxiao_button").show();
								$(".quxiao_button").attr('id','apply_job');
							}
						}*/
						
					}else{
						alert(rs[1]);
						location.reload();
					}
				}else if(rs[0]==2){
					if(equip == "wx"){
						location.href=rs[1]+"?equip="+equip;
					}else{
						location.href=rs[1];
					}
					
				}else{
					if(equip == "wx"){
						alert(rs[1]);
					}else{
						alert(rs[1]);
					}
				}
			}
		});
	});
	/**同意邀请职位--消息**/
	$('#message_yes').click(function(){
		var mid = $(this).attr('mid');
		var uid = $("#uid").val();
		var jobid = $("#i_jobid_"+mid).val();
		
		var ajax_url = "my.php?act=operate_company_interview&equip=wx&state=1&uid="+uid+"&jobid="+jobid+"&mid="+mid+"&t="+new Date().getTime();

		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){
				dialogShow('操作失败！！！');
			},
			success:function(rs){
				if(rs[0]==2){
					window.location.href=rs[1]; 
				}else{				
					dialogShow(rs[1]);
				}
			}
		});
	});
	/**拒绝邀请职位--消息**/
	$('#message_no').click(function(){
		var mid = $(this).attr('mid');
		var uid = $("#uid").val();
		var jobid = $("#i_jobid_"+mid).val();
		
		var ajax_url = "my.php?act=operate_company_interview&equip=wx&state=2&uid="+uid+"&jobid="+jobid+"&mid="+mid+"&t="+new Date().getTime();

		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){
				dialogShow('操作失败！！！');
			},
			success:function(rs){
				if(rs[0]==2){
					window.location.href=rs[1]; 
				}else{
					dialogShow(rs[1]);
				}
			}
		});
	});
	/**同意邀请职位--邀请**/
	$('#interv_yes').click(function(){
		var mid='';
		var jobid = $(this).attr('jid');
		var uid = $("#uid").val();
		
		var ajax_url = "my.php?act=operate_company_interview&equip=wx&state=1&uid="+uid+"&jobid="+jobid+"&mid="+mid+"&t="+new Date().getTime();
		
		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){
				dialogShow('操作失败！！！');
			},
			success:function(rs){
				if(rs[0]==2){
					window.location.href=rs[1]; 
				}else{				
					dialogShow(rs[1]);
				}
			}
		});
	});
	/**拒绝邀请职位--邀请**/
	$('#interv_no').click(function(){
		var mid='';
		var jobid = $(this).attr('jid');
		var uid = $("#uid").val();
		
		var ajax_url = "my.php?act=operate_company_interview&equip=wx&state=2&uid="+uid+"&jobid="+jobid+"&mid="+mid+"&t="+new Date().getTime();
		
		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){
				dialogShow('操作失败！！！');
			},
			success:function(rs){
				if(rs[0]==2){
					window.location.href=rs[1]; 
				}else{				
					dialogShow(rs[1]);
				}
			}
		});
	});
	
	/**同意到岗**/
	$('#sure').click(function(){
		var messageid = $(this).attr('mid');
		var uid = $("#uid").val();
		var jobid = $("#s_jobid_"+messageid).val();
		
		var ajax_url = "my.php?act=operate_message_list&equip=wx&state=1&uid="+uid+"&jobid="+jobid+"&messageid="+messageid+"&t="+new Date().getTime();
	//document.write(ajax_url);
		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){
				dialogShow('操作失败！！！');
			},
			success:function(rs){
				if(rs[0]==2){
					window.location.href=rs[1]; 
				}else{
					dialogShow(rs[1]);
				}
			}
		});
	});
	/**拒绝到岗**/
	$('#no_sure').click(function(){
		var messageid = $(this).attr('mid');
		var uid = $("#uid").val();
		var jobid = $("#s_jobid_"+messageid).val();
		
		var ajax_url = "my.php?act=operate_message_list&equip=wx&state=2&uid="+uid+"&jobid="+jobid+"&messageid="+messageid+"&t="+new Date().getTime();
		$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){
				dialogShow('操作失败！！！');
			},
			success:function(rs){
				if(rs[0]==2){
					window.location.href=rs[1]; 
				}else{
					dialogShow(rs[1]);
				}
			}
		});
	});
	
	/**定位打卡**/
	$('#sign').click(function(){
		var jobid = $("#jobid").val();
        var lat = $("#lat").val();
        var log = $("#log").val();
        var address = $("#address").val();

		//var ajax_url = "my.php?act=user_sign&equip=wx&sign_way=1&jobid="+jobid+"&lat="+lat+"&log="+log+"&address="+address;
        $.post('my.php?act=user_sign&sign_way=1',{jobid:jobid,lat:lat,log:log,address:address},function(rs){
            if(rs[0]==2){
                //dialogShow(rs[2]);
                alert(rs[2]);
                window.location.href=rs[1];
            }else{				
                alert(rs[1]);
                //dialogShow(rs[1]);
            }
        },'json')
		/*$.ajax({
			url: ajax_url,
			timeout: 5000,
			type: "POST",
			dataType: "json",
			error: function(){
				dialogShow('操作失败！！！');
			},
			success:function(rs){
				if(rs[0]==2){
                    dialogShow(rs[2]);
					window.location.href=rs[1];
				}else{				
					dialogShow(rs[1]);
				}
			}
		});*/
	});
    
    
    /**拍照打卡**/
	$('#sign_pic').click(function(){
		var jobid = $("#jobid").val();
          var media = '';
        $("input[name='media']").each(function(i){
            media += $(this).val() + ','; 
        });

        if(media == ''){
            return false;
        }

        $.post('my.php?act=user_sign_pic',{jobid:jobid,media:media},function(rs){
            if(rs[0]==2){
                dialogShow(rs[2]);
                window.location.href=rs[1];
            }else{				
                dialogShow(rs[1]);
            }
        },'json')

	});
    
    $("#sys").click(function(){
        wx.scanQRCode({
            needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
                var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果 
                $.post('my.php?act=user_sign&sign_way=2',{jobid:result},function(rs){
                    if(rs[0]==2){
                        dialogShow(rs[2]);
                        window.location.href=rs[1];
                    }else{
                        dialogShow(rs[1]);
                    }
                },'json')
            }
        });
    })


    $("li .fr").click(function(){
        
        if(!$(this).hasClass('on')){
            var num = $(".on").size();
            if(num >= 2){
                alert('最多只能设置2个时间点哦');
                return false;
            }
        }
        $(this).toggleClass("on");
    })   

    $("#sign_push_time").click(function(){
        var time = [];
        var timearr = ['7:00','8:40','13:00','15:00','17:00','19:00'];
        $("li .on").each(function(i){
           var t = $(this).parent().text();
           if($.inArray(t,timearr) < 0){
                alert('请选择正确的提醒时间');
                return false; 
           }
           time[i] = $(this).parent().text();
        })

        $.post('my.php',{act:'sign_push_time',time:time},function(rs){
            if(rs[0]==2){
                alert(rs[2]);
            }else{
                alert(rs[1]);
            }
        },'json')
    
    
    })

    function dialogShow(message){
        $("#dialog-info").html(message);
        // $(".ui-dialog").dialog("show");
    }
    
    
});

function dialogShow2(){
    $(".ui-dialog2").show();
}

function company_select_city(value){
    $("#work_city").hide();
    $("#city_search").empty();
    if(value){
        $.post("company.php?act=work_city",{sid:value},function(data){
            if(data.code == 1){
                var html = '<option value="">工作城市</option>';
                for(var i = 0; i<data.msg.length; i++){
                   html += "<option value='"+data.msg[i].id+"'>"+data.msg[i].categoryname+"</option>"; 
                }
                $("#city_search").append(html);
                $("#work_city").show();

            }else{
                alert(data.msg);
            }
        },'json')
    }
}

function buy_vip(id){
	if(id){
		var html='<li class="lineH36"><label>推荐码</label><input class="tjinp" name="recommend_code" id="recommend_code" type="text"></li> <li class="fontC02 mt5 fontS12" style="margin-left:70px;">购买会员推荐码为4位数字，如无人推荐可不填。</li> <li class="mt30 center"><a class="tjbtn" href="javascript:void(0)" onclick="buy_vip_vode('+id+')" >确定</a></li>';
		$("#tj_log").html(html);
		shadboxFun('tj_num');
		$("#tj_num").show();
				
	}
}
function buy_vip_vode(id){
		
	var recommend_code = $("#recommend_code").val();
	$.post("my.php?act=buy_vip",{id:id,recommend_code:recommend_code},function(data){
		
            if(data.result_code == 3){
				$("#tj_num").hide();
				$("body").append(data.result_msg);
				
                //$("#work_city").show();
            }
			if(data.result_code == 2){
				$("#tj_num").hide();
				var html = '<div class="jf_tit fontS18">购买失败</div><ul class="lineH24 mt15"><li>非常遗憾，购买失败！</li><li>'+data.result_msg+'</li></ul><div class="mt15 mb20"><a href="index.php" class="popbtn">回到首页</a><input class="popbtn popbox-close" type="button" value="查看精英券" /></div>';
                $("#pay_log").html(html);
				shadboxFun('pay');
        		$("#pay").show();
            }
			if(data.result_code == 0){	
							$("#tj_num").hide();
				var html = '<div class="jf_tit fontS18">购买失败</div><ul class="lineH24 mt15"><li>'+data.result_msg+'</li></ul><div class="mt15 mb20"><a href="index.php" class="popbtn">回到首页</a><input class="popbtn popbox-close" type="button" value="查看精英券" /></div>';
                $("#pay_log").html(html);
				shadboxFun('pay');
        		$("#pay").show();
			}
        },'json')
	
}
function dui_vip(id){
		
	if(id){
		$.post("my.php?act=buy_vip",{id:id},function(data){
            if(data.result_code == 3){
				$("#tj_num").hide();
				$("body").append(data.result_msg);
				
                //$("#work_city").show();
            }
			if(data.result_code == 0){
				$("#tj_num").hide();
				var html = '<div class="jf_tit fontS18">兑换失败</div><ul class="lineH24 mt15"><li>'+data.result_msg+'</li></ul><div class="mt15 mb20"><a href="index.php" class="popbtn">回到首页</a><input class="popbtn popbox-close" type="button" value="查看精英券" /></div>';
                $("#pay_log").html(html);
				shadboxFun('pay');
        		$("#pay").show();
            }
			if(data.result_code == 1){
				$("#tj_num").hide();
				var html = '<div class="jf_tit fontS18">'+data.result_msg+'</div><ul class="lineH24 mt15"><li>恭喜您，兑换成功！</li><<li>您的剩余有效兼职次数为'+data.nums+'次。</li><li>赶快去做兼职吧~</li></ul><div class="mt15 mb20"><a href="index.php" class="popbtn">回到首页</a><input class="popbtn popbox-close" type="button" value="查看精英券" /></div>';
                $("#pay_log").html(html);
				shadboxFun('pay');
        		$("#pay").show();
            }
			if(data.result_code == 2){
				$("#tj_num").hide();
				var html = '<div class="jf_tit fontS18">'+data.result_msg+'</div><ul class="lineH24 mt15"><li>非常遗憾，购卖失败！</li><li>您可退出后继续购卖</li></ul><div class="mt15 mb20"><a href="index.php" class="popbtn">回到首页</a><input class="popbtn popbox-close" type="button" value="查看精英券" /></div>';
                $("#pay_log").html(html);
				shadboxFun('pay');
        		$("#pay").show();
            }
        },'json')
	}
}
function IdentityCodeValid(code) { 
            var city={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江 ",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北 ",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏 ",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外 "};
            var tip = "";
            var pass= true;
            
            if(!code || !/^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i.test(code)){
                tip = "身份证号格式错误";
                pass = false;
				return false;
            }
            
           else if(!city[code.substr(0,2)]){
                tip = "地址编码错误";
                pass = false;
				return false;
            }
            else{
                //18位身份证需要验证最后一位校验位
                if(code.length == 18){
                    code = code.split('');
                    //∑(ai×Wi)(mod 11)
                    //加权因子
                    var factor = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ];
                    //校验位
                    var parity = [ 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 ];
                    var sum = 0;
                    var ai = 0;
                    var wi = 0;
                    for (var i = 0; i < 17; i++)
                    {
                        ai = code[i];
                        wi = factor[i];
                        sum += ai * wi;
                    }
                    var last = parity[sum % 11];
                    if(parity[sum % 11] != code[17]){
                        tip = "校验位错误";
                        pass =false;
						return false;
                    }
                }
            }
            if(!pass) alert(tip);
            return pass;
        }



//===================支付宝生活号 新增函数===============================

//获取验证码
function get_code(obj,needalipay){
    var alipay = $("#alipay").val();
    var tel = $("#mobile").val();
    mobile = /^(13|14|15|17|18|19)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
    if(!mobile.test(tel)){
        alert('请填写正确的手机号');
        return false;
    }

    if(!alipay && needalipay == 1){
        alert('系统繁忙请稍后再试');
        return false;
    }
    
    $(obj).attr("disabled", true);

    $.post('login.php',{'act':'get_captcha','mobile':tel,'alipay_id':alipay},function(data){
        if(data.result_code == 1){
            $.post('login.php',{'act':'send_mobile_auth','mobile':tel,'alipay_id':alipay,'code':data.code},function(res){
                if(res.sta == 1){
                    var count = 60;
                    var countdown = setInterval(CountDown, 1000);
                    function CountDown() {
                        $(obj).val(count + " 秒后重新获取");
                        if (count == 0) {
                            $(obj).val("重新获取").removeAttr("disabled");
                            clearInterval(countdown);
                        }
                        count--;
                    }
                }else{
                    $(obj).removeAttr("disabled");
                    alert(res.msg);
                }
            },'json') 
        }else{
            $(obj).removeAttr("disabled");
            alert(data.result_msg);
        }
    },'json')
}

//绑定支付宝等
function binding_other(redirect){
    var alipay = $("#alipay").val();
    var tel = $("#mobile").val();
    var code = $("#code").val();

    var tel = $("#mobile").val();
    mobile = /^(13|14|15|17|18|19)[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]$/;
    if(!mobile.test(tel)){
        alert('请填写正确的手机号');
        return false;
    }

    if(!code){
        alert('请填写验证码');
        return false;
    }

    if(!alipay){
        alert('系统繁忙请稍后再试');
        return false;
    }

     $.post('login.php',{'act':'binding_other','mobile':tel,'alipay_id':alipay,'code':code},function(data){
         alert(data.msg);
         if(data.sta == 1){
            window.location.href = redirect;
         }
     },'json')
}
